--POUR CONTROLE


define erp='erp_mli2.';
define outils='outils_mli2.';

--CREATE TABLE se_ctr_tarcat AS (SELECT * FROM &erp.ctr_tarcat WHERE 1=2);




DELETE FROM se_ctr_tarcat  ;


 INSERT INTO se_ctr_tarcat
 (SELECT id tarcat_cod,
         0 enreg_id,
         'N' enreg_s,
         libelle tarcat_lib,
         NULL tarcat_lib2,
         tarifttc tarttcht_typ
    FROM UV_CCOD_TARIFS) ;

 UPDATE se_ctr_tarcat tf SET enreg_id=(select enreg_id FROM &erp.ctr_tarcat f WHERE f.TARCAT_COD=tf.TARCAT_COD) ;
 UPDATE se_ctr_tarcat tf SET enreg_id=&outils.enreg_id.NEXTVAL WHERE enreg_id IS NULL OR enreg_id =0;



 CALL uvse_synchroverserp('TARCAT_COD','CTR_TARCAT','O') ;

 commit;
 
 
select * from (
SELECT &outils.stragg(source) source,tarcat_cod, enreg_id, enreg_s, tarcat_lib, tarcat_lib2, tarttcht_typ
FROM (
  SELECT 'uv' source ,g.* FROM se_ctr_tarcat g
  UNION ALL
  SELECT 'se' source ,g.* FROM &erp.ctr_tarcat g
  )
GROUP BY tarcat_cod, enreg_id, enreg_s, tarcat_lib, tarcat_lib2, tarttcht_typ
HAVING Count(1)!=2) r
ORDER BY tarcat_cod